package com.tancire.web.controller.platform.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.system.domain.SysMobileConfig;
import com.tancire.system.service.ISysMobileConfigService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 移动端配置Controller
 *
 * @author chenchao
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/system/sysMobileConfig")
public class SysMobileConfigController extends BaseController {

    @Resource
    private ISysMobileConfigService sysMobileConfigService;

    /**
     * 查询移动端配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:mobileConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMobileConfig sysMobileConfig) {
        startPage();
        List<SysMobileConfig> list = sysMobileConfigService.selectSysMobileConfigList(sysMobileConfig);
        return getDataTable(list);
    }

    /**
     * 查询移动端配置列表
     */
    @GetMapping("/list/config")
    public AjaxResult listConfig() {
        Object config = sysMobileConfigService.listConfig();
        return AjaxResult.success("查询成功", config);
    }

    /**
     * 导出移动端配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:mobileConfig:export')")
    @Log(title = "移动端配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMobileConfig sysMobileConfig) {
        List<SysMobileConfig> list = sysMobileConfigService.selectSysMobileConfigList(sysMobileConfig);
        ExcelUtil<SysMobileConfig> util = new ExcelUtil<SysMobileConfig>(SysMobileConfig.class);
        util.exportExcel(response, list, "移动端配置数据");
    }

    /**
     * 获取移动端配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:mobileConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysMobileConfigService.selectSysMobileConfigById(id));
    }

    /**
     * 新增移动端配置
     */
    @PreAuthorize("@ss.hasPermi('system:mobileConfig:add')")
    @Log(title = "移动端配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMobileConfig sysMobileConfig) {
        int count = sysMobileConfigService.insertSysMobileConfig(sysMobileConfig);
        sysMobileConfigService.asyncRedis();
        return toAjax(count);
    }

    /**
     * 修改移动端配置
     */
    @PreAuthorize("@ss.hasPermi('system:mobileConfig:edit')")
    @Log(title = "移动端配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMobileConfig sysMobileConfig) {
        int count = sysMobileConfigService.updateSysMobileConfig(sysMobileConfig);
        sysMobileConfigService.asyncRedis();
        return toAjax(count);
    }

    /**
     * 删除移动端配置
     */
    @PreAuthorize("@ss.hasPermi('system:mobileConfig:remove')")
    @Log(title = "移动端配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysMobileConfigService.deleteSysMobileConfigByIds(ids));
    }
}
